<template>
  <div>
    <SectionTitle class="section-title">已选订单</SectionTitle>
    <OrderSelectTable
      ref="orderTableRef"
      :cost-belong="costBelong"
      only-view
      @orderSelectedReset="orderSelectedReset"
    />
    <SectionTitle class="section-title">已选成本</SectionTitle>
    <CostTable
      ref="costTableRef"
      only-view
      @costSelectedReset="costSelectedReset"
    />
  </div>
</template>
<script>
import SectionTitle from '@/components/Title';
import OrderSelectTable from './OrderSelectTable';
import CostTable from './CostTable.vue';
export default {
  name: 'AllSelectedTable',
  components: {
    CostTable,
    OrderSelectTable,
    SectionTitle
  },
  props: {
    selectOrderList: {
      type: Array,
      default: () => []
    },
    selectCostList: {
      type: Array,
      default: () => []
    },
    costBelong: {
      type: Number | String,
      default: ''
    }
  },
  watch: {
    selectOrderList: {
      handler(list) {
        this.setOrderList(list);
      },
      immediate: true,
      deep: true
    },
    selectCostList: {
      handler(list) {
        this.setCostList(list);
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    setOrderList(list) {
      this.$refs['orderTableRef'] && this.$nextTick(() => {
        this.$refs['orderTableRef'].settleOrder.items = list;
        this.$refs['orderTableRef'].multipleSelectionAll = list;
        this.$refs['orderTableRef'].setSelectRow(list);
      });
    },
    setCostList(list) {
      this.$refs['costTableRef'] && this.$nextTick(() => {
        this.$refs['costTableRef'].settleOrder.items = list;
        this.$refs['costTableRef'].multipleSelectionAll = list;
        this.$refs['costTableRef'].setSelectRow(list);
      });
    },
    orderSelectedReset(selection) {
      this.setOrderList(selection);
      this.$emit('orderSelectedReset', selection);
    },
    costSelectedReset(selection) {
      this.setCostList(selection);
      this.$emit('costSelectedReset', selection);
    }
  }
};
</script>

<style lang="scss" scoped>
.section-title {
  margin: 16px 0 12px;
}
</style>
